Skip to content

fix: filter out $ref keys in bindings() to prevent undefined parser error#1196

Open
AayushSaini101 wants to merge 5 commits into
asyncapi:masterfrom
AayushSaini101:877
Open

fix: filter out $ref keys in bindings() to prevent undefined parser error#1196
AayushSaini101 wants to merge 5 commits into
asyncapi:masterfrom
AayushSaini101:877

Conversation

@AayushSaini101

@AayushSaini101 AayushSaini101 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Fixes #877

Related: #1167

When bindings objects still contain JSON reference keys, treat them as references rather than protocol names so Binding models are not built from invalid data.

…utput

Fixes asyncapi#877

When bindings objects still contain JSON reference keys, treat them as
references rather than protocol names so Binding models are not built
from invalid data.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f53a796

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/parser Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the microgrant Participation in the Microgrant Program label Jul 8, 2026
@aeworxet

aeworxet commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@asyncapi/microgrant_team

@aeworxet aeworxet moved this to In Progress in Microgrant Program Jul 8, 2026

@princerajpoot20 princerajpoot20 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the adeo file against this PR branch and still get document: undefined with the same schema-format error.

Can you try it on your end with this file and share the findings: https://github.com/asyncapi/spec/blob/master/examples/adeo-kafka-request-reply-asyncapi.yml

AayushSaini101 and others added 2 commits July 12, 2026 15:02
When a schema format is not registered, return the raw schema and continue
parsing so documents with bindings and other metadata remain accessible
without requiring AvroSchemaParser registration.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@AayushSaini101

Copy link
Copy Markdown
Collaborator Author

Done @princerajpoot20

image

Tested via this script:

import fs from 'node:fs';
import path from 'node:path';

import { AsyncAPIDocumentV3 } from '../../src/models';
import { Parser } from '../../src/parser';
import { filterLastVersionDiagnostics } from '../utils';

describe('Adeo case study spec', function() {
  const parser = new Parser();
  const specPath = path.join(__dirname, '../mocks/adeo-case-study.yaml');
  const spec = fs.readFileSync(specPath, 'utf8');

  it('should parse the Adeo case study document without registering AvroSchemaParser', async function() {
    const { document, diagnostics } = await parser.parse(spec, { source: specPath });

    expect(document).toBeInstanceOf(AsyncAPIDocumentV3);
    expect(document).toBeDefined();
    expect(filterLastVersionDiagnostics(diagnostics).length === 0).toEqual(true);

    const channel = document!.allChannels().get('costingRequestChannel');
    const responseChannel = document!.allChannels().get('costingResponseChannel');
    const operation = document!.allOperations().get('receiveACostingRequest');

    expect(document!.allServers()).toHaveLength(3);
    expect(document!.allServers().all().map(server => server.id())).toEqual([
      'production',
      'staging',
      'dev',
    ]);

    expect(channel?.address()).toEqual('adeo-{env}-case-study-COSTING-REQUEST-{version}');
    expect(channel?.bindings().get('kafka')?.json()).toEqual({
      replicas: 3,
      partitions: 3,
      topicConfiguration: {
        'cleanup.policy': ['delete'],
        'retention.ms': 60000000,
      },
    });

    expect(responseChannel?.address()).toBeNull();
    expect(responseChannel?.bindings().get('kafka')?.json()?.['x-key.subject.name.strategy']?.type).toEqual('string');

    expect(operation?.summary()).toContain('[COSTING]');
    expect(operation?.bindings().get('kafka')?.json()?.groupId?.type).toEqual('string');

    const requestMessage = document!.allMessages().find(msg => msg.name() === 'CostingRequestV1');
    expect(requestMessage?.title()).toEqual('Costing Request V1');
    expect(requestMessage?.payload()?.schemaFormat()).toEqual('application/vnd.apache.avro;version=1.9.0');
  });
});

export async function parseSchema(parser: Parser, input: ParseSchemaInput): Promise<AsyncAPISchema> {
const schemaParser = parser.parserRegistry.get(input.schemaFormat);
if (schemaParser === undefined) {
throw new Error('Unknown schema format');

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the reason it was failing for avro schema parsing, if there is any spec containing avro schema parsing, we need to register manually otherwise it will raise an error cc: @princerajpoot20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

microgrant Participation in the Microgrant Program

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Parser returns undefined when there's bindings in message

3 participants